/**
 * 游戏界面
 */
class Gameinfo extends ui.GameinfoUI {
    constructor() {
        super();
        this.startGame();
        this.play_sound.visible = false;
        this.final_score.visible = false;
        this.share_icon.visible = false;
        Laya.SoundManager.muted = true;
        this.btn_pause.on(Laya.Event.CLICK, this, this.pauseGame);
        this.btn_start.on(Laya.Event.CLICK, this, this.startGame);
        this.btn_restart.on(Laya.Event.CLICK, this, this.restartGame);
        this.play_sound.on(Laya.Event.CLICK, this, this.onSound);
        this.no_sound.on(Laya.Event.CLICK, this, this.onSound);
        this.share_icon.on(Laya.Event.CLICK, this, this.shareGame);
    }
    //分享游戏
    public shareGame(): void {
        Laya.Browser.window.wx.shareAppMessage({
            title: '最新分数 ' + GameMain.total_score + '分',
            imageUrl: GameMain.share_log_img
        })
    }

    //开发音效
    public onSound(): void {
        if(this.play_sound.visible) {
            Laya.SoundManager.muted = true;
            this.play_sound.visible = false;
            this.no_sound.visible = true;
        }else{
            Laya.SoundManager.muted = false;
            this.no_sound.visible = false;
            this.play_sound.visible = true;
        }
    }
    public setHeroHp(_hp: number): void {
        this.hero_hp.text = "hp:" + _hp;
    }
    public setHeroScore(_score: number): void {
        this.hero_score.text = "score:" + _score;
    }
    public setGameLevel(_level: number): void {
        this.game_level.text = "level:" + _level;
    }
    public pauseGame(): void {
        this.game_status_label.visible = true;
        this.btn_start.visible = true;
        this.btn_restart.visible = true;
        Main.is_playing = false;
        this.game_status_label.text = '游戏暂停';
    }
    public endGame(): void {
        this.game_status_label.visible = true;
        this.btn_restart.visible = true;
        Main.is_playing = false;
        this.final_score.text = "得分 " + GameMain.total_score;
        this.final_score.visible = true;
        this.share_icon.visible = true;
        this.game_status_label.text = 'GAME OVER !';
    }
    private startGame(): void {
        this.game_status_label.visible = false;
        this.btn_start.visible = false;
        this.btn_restart.visible = false;
        this.share_icon.visible = false;
        this.final_score.visible = false;
        Main.is_playing = true;
    }
    public restartGame(): void {
        this.startGame();
        this.setHeroScore(0);
        this.setGameLevel(1);
        GameMain.onStart();
    }
}